﻿Imports BUS
Imports DTO

Public Class frmtracuunhanvien

    Dim nv As New NhanVienCRT()

    Private Sub frmtracuunhanvien_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim busbc As New BangCapBUS()
        LookUpbangcap.Properties.DataSource = busbc.LayDSBangCap()
        LookUpbangcap.Properties.DisplayMember = "TenBangCap"
        LookUpbangcap.Properties.ValueMember = "MaBangCap"
        LookUpbangcap.EditValue = 3

        Dim busbp As New BoPhanBUS()
        LookUpbophan.Properties.DataSource = busbp.LayDSBoPhan()
        LookUpbophan.Properties.DisplayMember = "TenBoPhan"
        LookUpbophan.Properties.ValueMember = "MaBoPhan"
        LookUpbophan.EditValue = 1

        Dim buscv As New ChucVuBUS()
        LookUpchucvu.Properties.DataSource = buscv.LayDSChucVu()
        LookUpchucvu.Properties.DisplayMember = "TenChucVu"
        LookUpchucvu.Properties.ValueMember = "MaChucVu"
        LookUpchucvu.EditValue = 5
    End Sub

    Private Sub chkngaysinh_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkngaysinh.CheckedChanged
        If chkngaysinh.Checked Then
            DateEditngaysinhtu.Enabled = True
            DateEditngaysinhden.Enabled = True
        Else
            DateEditngaysinhtu.Enabled = False
            DateEditngaysinhden.Enabled = False
        End If
    End Sub

    Private Sub chkdiachi_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkdiachi.CheckedChanged
        If chkdiachi.Checked Then
            txtdiachi.Enabled = True
        Else
            txtdiachi.Enabled = False
        End If
    End Sub

    Private Sub chkdienthoai_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkdienthoai.CheckedChanged
        If chkdienthoai.Checked Then
            txtdienthoai.Enabled = True
        Else
            txtdienthoai.Enabled = False
        End If
    End Sub

    Private Sub CheckEdit4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkbangcap.CheckedChanged
        If chkbangcap.Checked Then
            LookUpbangcap.Enabled = True
        Else
            LookUpbangcap.Enabled = False
        End If
    End Sub

    Private Sub chkbophan_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkbophan.CheckedChanged
        If chkbophan.Checked Then
            LookUpbophan.Enabled = True
        Else
            LookUpbophan.Enabled = False
        End If
    End Sub

    Private Sub chkchucvu_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        
    End Sub

    Private Sub chkchucvu_CheckedChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkchucvu.CheckedChanged
        If chkchucvu.Checked Then
            LookUpchucvu.Enabled = True
        Else
            LookUpchucvu.Enabled = False
        End If
    End Sub

    Private Sub CapNhatTieuChuanTraCuu(ByVal a As Boolean)
        If a = True Then
            If txtmaso.Text <> "" Then
                nv.MaNhanVien = Integer.Parse(txtmaso.Text)
            Else
                nv.MaNhanVien = 0
            End If

            nv.HoTen = txthoten.Text
            nv.NgaySinhTu = DateEditngaysinhtu.DateTime
            nv.NgaySinhDen = DateEditngaysinhden.DateTime
            nv.DiaChi = txtdiachi.Text
            nv.DienThoai = txtdienthoai.Text
            nv.MaBangCap = LookUpbangcap.EditValue
            nv.MaBoPhan = LookUpbophan.EditValue
            nv.MaChucVu = LookUpchucvu.EditValue

            nv.ChkNgaySinh = chkngaysinh.Checked
            nv.ChkDiaChi = chkdiachi.Checked
            nv.ChkBangCap = chkbangcap.Checked
            nv.ChkBoPhan = chkbophan.Checked
            nv.ChkChuVu = chkchucvu.Checked
            nv.ChkDienThoai = chkdienthoai.Checked
        End If
    End Sub

    Private Sub btntracuu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntracuu.Click
        Try
            CapNhatTieuChuanTraCuu(True)
            Dim nvBus As New NhanVienBUS()
            Dim dtHS As DataTable
            dtHS = nvBus.TimKiem(nv)
            dtgvnhanvien.DataSource = dtHS
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
End Class